package one.stand.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import one.stand.aop.ApiController;
import one.stand.model.ResultModel;
import one.stand.request.AddShareCountRequest;
import one.stand.request.CreateShareRecordRequest;
import one.stand.request.statistics.share.ShareTopNRequest;
import one.stand.request.statistics.share.ShareTypeDetailsStatisticsRequest;
import one.stand.request.statistics.share.SituationShareStatisticsRequest;
import one.stand.response.statistics.share.ShareTypeDetailsStatisticsRepository;
import one.stand.response.statistics.share.ShareUserTopNResponse;
import one.stand.response.statistics.share.SituationShareStatisticsResponse;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 分享记录 controller
 * Created by renz on 2019/10/23 23:06
 */
@RestController
@RequestMapping("crmApi/shareRecord")
@Api(description = "分享记录系列",tags="分享记录系列")
public class ShareRecordController extends BaseController {

    @PostMapping("/addShareRecord")
    @ApiOperation(value = "添加分享记录")
    @ApiImplicitParams({ @ApiImplicitParam(name = "companyId", value = "被查看的企业ID", required = true, paramType = "Integer"),
                         @ApiImplicitParam(name = "shareType", value = "分享类型 1:名片，2:商品，3:预约，4:文章", required = true, paramType = "Integer"),
                         @ApiImplicitParam(name = "itemId", value = "分享对象id 名片id、商品id、预约产品id、文章id", required = true, paramType = "Integer"), })
    @ApiController(isLogin = true, paramClass = CreateShareRecordRequest.class)
    public ResultModel<Integer> addShareRecord(@RequestAttribute CreateShareRecordRequest request) {
        request.setUserId(request.getId().intValue());
        request.setCardId(request.getCardId());
        return crmFegin.addShareRecord(request);
    }

    /**
     * 添加打开分享次数
     */
    @PostMapping("/addOpenShareCount")
    @ApiOperation(value = "添加分享记录")
    @ApiImplicitParams({ @ApiImplicitParam(name = "shareRecordId", value = "分享Id", paramType = "Integer"),
                         @ApiImplicitParam(name = "uuid", value = "前端生成的uuid", paramType = "String") })
    @ApiController(isLogin = true, paramClass = AddShareCountRequest.class)
    public ResultModel<Boolean> addOpenShareCount(@RequestAttribute AddShareCountRequest request) {
        return crmFegin.addOpenShareCount(request);
    }

    /**
     * 行为分析统计
     */
    @PostMapping("/situationStatistics")
    @ApiOperation(value = "行为分析统计")
    @ApiImplicitParams({ @ApiImplicitParam(name = "timeType", value = "统计类型 0:今日;1:昨日;2:7天;3:30天", required = true, paramType = "Integer") })
    @ApiController(isLogin = true, paramClass = SituationShareStatisticsRequest.class)
    public ResultModel<SituationShareStatisticsResponse> situationShareStatistics(@RequestAttribute SituationShareStatisticsRequest request) {
        request.setCompanyId(request.getCId().intValue());
        return crmFegin.situationShareStatistics(request);
    }

    /**
     * topN
     */
    @PostMapping("/topN")
    @ApiOperation(value = "topN")
    @ApiImplicitParams({ @ApiImplicitParam(name = "timeType", value = "统计类型 0:今日;1:昨日;2:7天;3:30天", required = true, paramType = "Integer"),
                         @ApiImplicitParam(name = "topN", value = "topN 数值", required = false, paramType = "Integer"), })
    @ApiController(isLogin = true, paramClass = ShareTopNRequest.class)
    public ResultModel<List<ShareUserTopNResponse>> shareTopN(@RequestAttribute ShareTopNRequest request) {
        request.setCompanyId(request.getCId().intValue());
        return crmFegin.shareTopN(request);
    }

    /**
     * 分享类别明细统计
     */
    @PostMapping("/shareTypeDetailsStatistics")
    @ApiOperation(value = "分享类别明细统计")
    @ApiImplicitParams({ @ApiImplicitParam(name = "timeType", value = "统计类型 0:今日;1:昨日;2:7天;3:30天", required = true, paramType = "Integer"),
                         @ApiImplicitParam(name = "shareUserId", value = "分享的用户ID", required = true, paramType = "Integer"), })
    @ApiController(isLogin = true, paramClass = ShareTypeDetailsStatisticsRequest.class)
    public ResultModel<List<ShareTypeDetailsStatisticsRepository>> shareTypeDetailsStatistics(@RequestAttribute ShareTypeDetailsStatisticsRequest request) {
        request.setCompanyId(request.getCId().intValue());
        return crmFegin.shareTypeDetailsStatistics(request);
    }
}
